package com.ctg.edas.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;

@RestController
@RequestMapping("/nacos/consumer")
public class ConsumerController {

    @Autowired
    private ProviderFeign providerfeign;

    @GetMapping("/call")
    public String call() {
        return providerfeign.echo();
    }

    @GetMapping("/echo")
    public String echo() {
        String ip = "";
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        }  catch (Exception e) {

            e.printStackTrace();
        }
        if (StringUtils.isEmpty(ip)) {
            return "Spring Cloud客户端";
        }
        return "Spring Cloud客户端 [" + ip + "]！branch is develop!v6.0.0";
    }

    @GetMapping("/alive")
    public Boolean alive() {
        return Boolean.TRUE;
    }

    @GetMapping("/slow")
    public String slow(@RequestParam(value = "second") Integer second) {
        return providerfeign.slow(second);
    }
}
